mdbt42q 2.2.0
Loading...
Searching...
No Matches
mdbt42q.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef MDBT42Q_H
29#define MDBT42Q_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_uart.h"
52
58
63
68
73#define MDBT42Q_CMD_SET_PARAM_DEVICE_NAME "AT+NAME"
74#define MDBT42Q_CMD_SET_BAUDRATE_9600 "AT+BAUDRATE9600"
75#define MDBT42Q_CMD_SET_BAUDRATE_19200 "AT+BAUDRATE19200"
76#define MDBT42Q_CMD_SET_BAUDRATE_38400 "AT+BAUDRATE38400"
77#define MDBT42Q_CMD_SET_BAUDRATE_57600 "AT+BAUDRATE57600"
78#define MDBT42Q_CMD_SET_BAUDRATE_115200 "AT+BAUDRATE115200"
79#define MDBT42Q_CMD_SET_BAUDRATE_230400 "AT+BAUDRATE230400"
80#define MDBT42Q_CMD_SET_BAUDRATE_460800 "AT+BAUDRATE460800"
81#define MDBT42Q_CMD_ENABLE_FLOW_CONTROL "AT+FLOWCONTROLEN"
82#define MDBT42Q_CMD_DISABLE_FLOW_CONTROL "AT+FLOWCONTROLDIS"
83#define MDBT42Q_CMD_SET_TX_POWER_4DBM "AT+TXPOWER4DBM"
84#define MDBT42Q_CMD_SET_TX_POWER_0DBM "AT+TXPOWER0DBM"
85#define MDBT42Q_CMD_SET_TX_POWER_MINUS_4DBM "AT+TXPOWER-4DBM"
86#define MDBT42Q_CMD_SET_TX_POWER_MINUS_8DBM "AT+TXPOWER-8DBM"
87#define MDBT42Q_CMD_SET_TX_POWER_MINUS_20DBM "AT+TXPOWER-20DBM"
88#define MDBT42Q_CMD_USE_INTERNAL_XTAL "AT+XTALINTERNAL"
89#define MDBT42Q_CMD_USE_EXTERNAL_XTAL "AT+XTALEXTERNAL"
90#define MDBT42Q_CMD_SET_CONNECT_IND_LOW "AT+CONNECTINDICATORLOW"
91#define MDBT42Q_CMD_SET_CONNECT_IND_HIGH "AT+CONNECTINDICATORHIGH"
92#define MDBT42Q_CMD_SET_PHYMODE_1MBPS "AT+PHYMODE1MBPS"
93#define MDBT42Q_CMD_SET_PHYMODE_2MBPS "AT+PHYMODE2MBPS"
94#define MDBT42Q_CMD_SET_WAKEUP_LOW "AT+WAKEUPLOW"
95#define MDBT42Q_CMD_SET_WAKEUP_HIGH "AT+WAKEUPHIGH"
96#define MDBT42Q_CMD_SET_PARAM_ADV_TIME "AT+ADVTIME"
97#define MDBT42Q_CMD_DISABLE_DCDC "AT+DCDCDIS"
98#define MDBT42Q_CMD_ENABLE_DCDC "AT+DCDCEN"
99#define MDBT42Q_CMD_SET_CONN_INTERVAL_MODE_0 "AT+CONNECTINTERVALMODE0"
100#define MDBT42Q_CMD_SET_CONN_INTERVAL_MODE_1 "AT+CONNECTINTERVALMODE1"
101#define MDBT42Q_CMD_SET_CONN_INTERVAL_MODE_2 "AT+CONNECTINTERVALMODE2"
102#define MDBT42Q_CMD_SET_PARAM_CONN_INTERVAL_T "AT+CONNECTINTERVALTIME"
103#define MDBT42Q_CMD_SET_PARAM_ADV_LED_PATTERN "AT+ADVPATTERN"
104#define MDBT42Q_CMD_SET_PARAM_CONN_LED_PATTERN "AT+CONNECTPATTERN"
105#define MDBT42Q_CMD_SET_PARAM_SERIAL_NUMBER "AT+SERIALNO"
106#define MDBT42Q_CMD_DISABLE_RESPONSE "AT+RESPONSEDIS"
107#define MDBT42Q_CMD_ENABLE_RESPONSE "AT+RESPONSEEN"
108#define MDBT42Q_CMD_SET_PARAM_MAC_ADDRESS "AT+MACADDR"
109#define MDBT42Q_CMD_RESET "AT+RESET"
110#define MDBT42Q_CMD_ADV_START "AT+ADVSTART"
111#define MDBT42Q_CMD_ADV_STOP "AT+ADVSTOP"
112#define MDBT42Q_CMD_ENTER_SLEEP "AT+SLEEP"
113#define MDBT42Q_CMD_DISCONNECT "AT+DISCONNECT"
114#define MDBT42Q_CMD_RESTORE_DEFAULT "AT+DEFAULT"
115#define MDBT42Q_CMD_SET_GPIO_12_HIGH "AT+SETGPIO12HIGH"
116#define MDBT42Q_CMD_SET_GPIO_13_HIGH "AT+SETGPIO13HIGH"
117#define MDBT42Q_CMD_SET_GPIO_14_HIGH "AT+SETGPIO14HIGH"
118#define MDBT42Q_CMD_SET_GPIO_15_HIGH "AT+SETGPIO15HIGH"
119#define MDBT42Q_CMD_SET_GPIO_16_HIGH "AT+SETGPIO16HIGH"
120#define MDBT42Q_CMD_SET_GPIO_17_HIGH "AT+SETGPIO17HIGH"
121#define MDBT42Q_CMD_SET_GPIO_18_HIGH "AT+SETGPIO18HIGH"
122#define MDBT42Q_CMD_SET_GPIO_19_HIGH "AT+SETGPIO19HIGH"
123#define MDBT42Q_CMD_SET_GPIO_12_LOW "AT+SETGPIO12LOW"
124#define MDBT42Q_CMD_SET_GPIO_13_LOW "AT+SETGPIO13LOW"
125#define MDBT42Q_CMD_SET_GPIO_14_LOW "AT+SETGPIO14LOW"
126#define MDBT42Q_CMD_SET_GPIO_15_LOW "AT+SETGPIO15LOW"
127#define MDBT42Q_CMD_SET_GPIO_16_LOW "AT+SETGPIO16LOW"
128#define MDBT42Q_CMD_SET_GPIO_17_LOW "AT+SETGPIO17LOW"
129#define MDBT42Q_CMD_SET_GPIO_18_LOW "AT+SETGPIO18LOW"
130#define MDBT42Q_CMD_SET_GPIO_19_LOW "AT+SETGPIO19LOW"
131#define MDBT42Q_CMD_SET_GPIO_12_OFF "AT+SETGPIO12OFF"
132#define MDBT42Q_CMD_SET_GPIO_13_OFF "AT+SETGPIO13OFF"
133#define MDBT42Q_CMD_SET_GPIO_14_OFF "AT+SETGPIO14OFF"
134#define MDBT42Q_CMD_SET_GPIO_15_OFF "AT+SETGPIO15OFF"
135#define MDBT42Q_CMD_SET_GPIO_16_OFF "AT+SETGPIO16OFF"
136#define MDBT42Q_CMD_SET_GPIO_17_OFF "AT+SETGPIO17OFF"
137#define MDBT42Q_CMD_SET_GPIO_18_OFF "AT+SETGPIO18OFF"
138#define MDBT42Q_CMD_SET_GPIO_19_OFF "AT+SETGPIO19OFF"
139#define MDBT42Q_CMD_GET_DEVICE_NAME "AT?NAME"
140#define MDBT42Q_CMD_GET_VERSION "AT?VERSION"
141#define MDBT42Q_CMD_GET_MAC_ADDRESS "AT?MACADDR"
142#define MDBT42Q_CMD_GET_BAUD_RATE "AT?BAUDRATE"
143#define MDBT42Q_CMD_GET_FLOW_CONTROL "AT?FLOWCONTROL"
144#define MDBT42Q_CMD_GET_TX_POWER "AT?TXPOWER"
145#define MDBT42Q_CMD_GET_OSCILLATOR "AT?XTAL"
146#define MDBT42Q_CMD_GET_CONNECT_INDICATOR "AT?CONNECTINDICATOR"
147#define MDBT42Q_CMD_GET_PHY_MODE "AT?PHYMODE"
148#define MDBT42Q_CMD_GET_WAKEUP_MODE "AT?WAKEUP"
149#define MDBT42Q_CMD_GET_ADV_TIME "AT?ADVTIME"
150#define MDBT42Q_CMD_GET_DCDC_STATUS "AT?DCDC"
151#define MDBT42Q_CMD_GET_CONN_INTERVAL_MODE "AT?CONNECTINTERVALMODE"
152#define MDBT42Q_CMD_GET_ADV_LED_PATTERN "AT?ADVPATTERN"
153#define MDBT42Q_CMD_GET_CONN_LED_PATTERN "AT?CONNECTPATTERN"
154#define MDBT42Q_CMD_GET_SERIAL_NUMBER "AT?SERIALNO"
155#define MDBT42Q_CMD_GET_ADC_VALUE "AT?ADCVALUE"
156#define MDBT42Q_CMD_GET_RESPONSE_MODE "AT?RESPONSE"
157#define MDBT42Q_CMD_GET_ALL_PARAMETERS "AT?ALLPARAMETERS"
158#define MDBT42Q_CMD_GET_CONN_INTERVAL_TIME "AT?CONNECTINTERVALTIME"
159
165#define MDBT42Q_TX_DRV_BUFFER_SIZE 200
166#define MDBT42Q_RX_DRV_BUFFER_SIZE 600
167 // mdbt42q_cmd
169
174
179
184#define MDBT42Q_MAP_MIKROBUS( cfg, mikrobus ) \
185 cfg.tx_pin = MIKROBUS( mikrobus, MIKROBUS_TX ); \
186 cfg.rx_pin = MIKROBUS( mikrobus, MIKROBUS_RX ); \
187 cfg.ind = MIKROBUS( mikrobus, MIKROBUS_AN ); \
188 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
189 cfg.cts = MIKROBUS( mikrobus, MIKROBUS_CS ); \
190 cfg.pd = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
191 cfg.rts = MIKROBUS( mikrobus, MIKROBUS_INT );
192 // mdbt42q_map // mdbt42q
195
200typedef struct
201{
202 // Output pins
203 digital_out_t rst;
204 digital_out_t cts;
205 digital_out_t pd;
206
207 // Input pins
208 digital_in_t ind;
209 digital_in_t rts;
210
211 // Modules
212 uart_t uart;
213
214 // Buffers
218
219} mdbt42q_t;
220
225typedef struct
226{
227 // Communication gpio pins
228 pin_name_t rx_pin;
229 pin_name_t tx_pin;
230
231 // Additional gpio pins
232 pin_name_t ind;
233 pin_name_t rst;
234 pin_name_t cts;
235 pin_name_t pd;
236 pin_name_t rts;
237
238 // Static variable
239 uint32_t baud_rate;
241 uart_data_bits_t data_bit;
242 uart_parity_t parity_bit;
243 uart_stop_bits_t stop_bit;
244
246
258
264
275
290
303err_t mdbt42q_generic_write ( mdbt42q_t *ctx, uint8_t *data_in, uint16_t len );
304
317err_t mdbt42q_generic_read ( mdbt42q_t *ctx, uint8_t *data_out, uint16_t len );
318
328void mdbt42q_set_rst_pin ( mdbt42q_t *ctx, uint8_t state );
329
339void mdbt42q_set_pd_pin ( mdbt42q_t *ctx, uint8_t state );
340
350void mdbt42q_set_cts_pin ( mdbt42q_t *ctx, uint8_t state );
351
361
371
381
391void mdbt42q_cmd_run ( mdbt42q_t *ctx, uint8_t *cmd );
392
403void mdbt42q_cmd_set ( mdbt42q_t *ctx, uint8_t *cmd, uint8_t *value );
404
405#ifdef __cplusplus
406}
407#endif
408#endif // MDBT42Q_H
409 // mdbt42q
411
412// ------------------------------------------------------------------------ END
#define MDBT42Q_RX_DRV_BUFFER_SIZE
Definition mdbt42q.h:166
#define MDBT42Q_TX_DRV_BUFFER_SIZE
MDBT42Q driver buffer size.
Definition mdbt42q.h:165
void mdbt42q_cmd_run(mdbt42q_t *ctx, uint8_t *cmd)
MDBT42Q cmd run function.
err_t mdbt42q_generic_write(mdbt42q_t *ctx, uint8_t *data_in, uint16_t len)
MDBT42Q data writing function.
void mdbt42q_set_pd_pin(mdbt42q_t *ctx, uint8_t state)
MDBT42Q set PD pin function.
void mdbt42q_set_rst_pin(mdbt42q_t *ctx, uint8_t state)
MDBT42Q set RST pin function.
uint8_t mdbt42q_get_ind_pin(mdbt42q_t *ctx)
MDBT42Q get IND pin function.
void mdbt42q_reset_device(mdbt42q_t *ctx)
MDBT42Q reset device function.
err_t mdbt42q_generic_read(mdbt42q_t *ctx, uint8_t *data_out, uint16_t len)
MDBT42Q data reading function.
void mdbt42q_cfg_setup(mdbt42q_cfg_t *cfg)
MDBT42Q configuration object setup function.
err_t mdbt42q_init(mdbt42q_t *ctx, mdbt42q_cfg_t *cfg)
MDBT42Q initialization function.
void mdbt42q_set_cts_pin(mdbt42q_t *ctx, uint8_t state)
MDBT42Q set CTS pin function.
void mdbt42q_cmd_set(mdbt42q_t *ctx, uint8_t *cmd, uint8_t *value)
MDBT42Q cmd set function.
uint8_t mdbt42q_get_rts_pin(mdbt42q_t *ctx)
MDBT42Q get RTS pin function.
mdbt42q_return_value_t
MDBT42Q Click return value data.
Definition mdbt42q.h:252
@ MDBT42Q_ERROR_TIMEOUT
Definition mdbt42q.h:255
@ MDBT42Q_OK
Definition mdbt42q.h:253
@ MDBT42Q_ERROR
Definition mdbt42q.h:254
MDBT42Q Click configuration object.
Definition mdbt42q.h:226
pin_name_t rts
Definition mdbt42q.h:236
uint32_t baud_rate
Definition mdbt42q.h:239
pin_name_t cts
Definition mdbt42q.h:234
bool uart_blocking
Definition mdbt42q.h:240
uart_data_bits_t data_bit
Definition mdbt42q.h:241
pin_name_t tx_pin
Definition mdbt42q.h:229
pin_name_t rx_pin
Definition mdbt42q.h:228
uart_stop_bits_t stop_bit
Definition mdbt42q.h:243
pin_name_t pd
Definition mdbt42q.h:235
uart_parity_t parity_bit
Definition mdbt42q.h:242
pin_name_t rst
Definition mdbt42q.h:233
pin_name_t ind
Definition mdbt42q.h:232
MDBT42Q Click context object.
Definition mdbt42q.h:201
uint8_t uart_tx_buffer[MDBT42Q_TX_DRV_BUFFER_SIZE]
Definition mdbt42q.h:216
uint8_t uart_rx_buffer[MDBT42Q_RX_DRV_BUFFER_SIZE]
Definition mdbt42q.h:215
uint8_t cmd_buffer[MDBT42Q_TX_DRV_BUFFER_SIZE]
Definition mdbt42q.h:217
digital_out_t pd
Definition mdbt42q.h:205
uart_t uart
Definition mdbt42q.h:212
digital_in_t rts
Definition mdbt42q.h:209
digital_out_t rst
Definition mdbt42q.h:203
digital_in_t ind
Definition mdbt42q.h:208
digital_out_t cts
Definition mdbt42q.h:204